const attendsModel = require('../models/attendsModel')
// 考勤记录添加
exports.add = async (req, res) => {
    let { student_id, date, status, remarks, score } = req.body
    try {
        let results = await attendsModel.add(student_id, date, status, remarks, score)
        console.log(results)
        res.json({ code: 0, msg: "考勤记录添加成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 考勤记录的删除- 软删除
exports.del_f = async (req, res) => {
    let { id } = req.query
    try {
        let results = await attendsModel.del_f(id)
        console.log(results)
        res.json({ code: 0, msg: "考勤记录删除成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 考勤记录的删除- 真删除
exports.del_t = async (req, res) => {
    let { id } = req.query
    try {
        let results = await attendsModel.del_t(id)
        console.log(results)
        res.json({ code: 0, msg: "考勤记录删除成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 考勤记录的获取数据
exports.get = async (req, res) => {
    let { id } = req.query
    try {
        let results = await attendsModel.get(id)
        console.log(results)
        res.json({ code: 0, msg: "考勤记录的获取数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 考勤记录的设置数据
exports.set = async (req, res) => {
    let { id, student_id, date, status, remarks, score } = req.body
    try {
        let results = await attendsModel.set(id, student_id, date, status, remarks, score)
        console.log(results)
        res.json({ code: 0, msg: "考勤记录的设置数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 考勤的列表搜索分页
exports.list = async (req, res) => {
    let { student_name, student_id, class_id, program_id, status, date, page, page_size } = req.query
    try {
        let results = await attendsModel.list(student_name, student_id, class_id, program_id, status, date, Number(page), Number(page_size))
        console.log(results)
        res.json({ code: 0, msg: "考勤的列表搜索分页数据请求成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 获取所有学生
exports.allStudent = async (req, res) => {
    let {class_id} = req.query
    try {
        let results = await attendsModel.all_student(class_id)
        console.log(results)
        res.json({ code: 0, msg: "获取所有学生数据请求成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 根据传过来的学生id给出对应的学生学号
exports.studentIdTo = async (req, res) => {
    let { student_id } = req.query
    try {
        let results = await attendsModel.studentIdToM(student_id)
        console.log(results)
        res.json({ code: 0, msg: "对应的学生学号数据请求成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}